home *** CD-ROM | disk | FTP | other *** search
- Message-ID: <110310Z22031996@anon.penet.fi>
- Path: news.eunet.fi!anon.penet.fi
- Newsgroups: comp.lang.c
- From: an25305@anon.penet.fi (Cdr. Coriander Salamander)
- X-Anonymously-To: comp.lang.c
- Organization: Anonymous forwarding service
- Reply-To: an25305@anon.penet.fi
- Date: Fri, 22 Mar 1996 10:53:11 UTC
- Subject: Re: rand ?
- References: <4idjt4$4du@itsop2.its.brooklyn.cuny.edu> <314BB352.2734@ccis.com>
-
- In article <314BB352.2734@ccis.com>, Derek Lund <wlund@ccis.com> writes:
- > #define RANDOMIZE() srand(time(NULL)) /* time() is in time.h */
-
- This may fail on machines without prototypes. Safer is
- srand((unsigned int)time((time_t *)NULL)) .
-
- > int random(int i)
- > {
- > double x = RAND_MAX + 1.0 ;/* RAND_MAX is defined in stdlib.h */
- > int y ;
- > RANDOMIZE();
- > y = 1 + rand() * (i /x) ;
- > return y ;
- > }
-
- It's a *horrible* idea to call srand() (or anything which calls it) once
- for each time you call rand(). You won't get "more random" numbers this
- way, in fact you'll get less random. If you call this random() five
- times in one second, you'll get the same number back each time.
-
- Since you should typically call srand() just once, there's hardly any
- need to encapsulate it in a macro.
-
- --****ATTENTION****--****ATTENTION****--****ATTENTION****--***ATTENTION***
- Your e-mail reply to this message WILL be *automatically* ANONYMIZED.
- Please, report inappropriate use to abuse@anon.penet.fi
- For information (incl. non-anon reply) write to help@anon.penet.fi
- If you have any problems, address them to admin@anon.penet.fi
-